using UnityEngine;
using System.Collections;

public class UtilsString {
	
	public static string formatTimeString(int time, bool[] timeFormat){
		int c = 0;
		
		int hours = 0, mins = 0, secs = 0;
		if(time<0) time = 0;
		if(timeFormat[0]==true){
			hours = Mathf.FloorToInt(time/3600000);
			time -= hours*3600000;
			c++;
		}
		if(timeFormat[1]==true){
			mins = Mathf.FloorToInt(time/60000);
			time -= mins*60000;
			c++;
		}
		if(timeFormat[2]==true){
			secs = Mathf.FloorToInt(time/1000);
			time -= secs*1000;
			c++;
		}
		if(timeFormat[3]==true) c++;
		int mils = Mathf.FloorToInt(time/10);
		
		string shours = (hours<10)? "0"+hours : ""+hours;
		string smins = (mins<10)? "0"+mins : ""+mins;
		string ssecs = (secs<10)? "0"+secs : ""+secs;
		string smils = (mils<10)? "0"+mils : ""+mils;
		
		string[] tarr = new string[c];
		int i = 0;
		if(timeFormat[0]==true) tarr[i++] = shours;
		if(timeFormat[1]==true) tarr[i++] = smins;
		if(timeFormat[2]==true) tarr[i++] = ssecs;
		if(timeFormat[3]==true) tarr[i++] = smils;
		
		string result = "";
		i=0;
		for(; i<c; ++i){
			result += tarr[i]+(i<c-1 ? ":" : "");	
		}
		
		return result;
	}
	
}

